import Vue from "vue"
import { Message } from 'element-ui'

Vue.directive('copy', {
    bind: function(el, binding) {
      el.$copy = function() {
        const textarea = document.createElement('textarea');
        textarea.value = binding.value;
        document.body.appendChild(textarea);
        textarea.select();
        document.execCommand('Copy');
        document.body.removeChild(textarea);
        Message('复制成功！')
      }
      el.addEventListener('click', el.$copy);
    },
    unbind: function(el) {
      el.removeEventListener('click', el.$copy);
    }
  });